package com.breakfast.fun.view.viewholder;

import android.app.Activity;
import android.app.ActivityOptions;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.breakfast.fun.R;
import com.breakfast.fun.base.BaseViewHolder;
import com.breakfast.fun.data.repository.ToolRepository;
import com.breakfast.fun.ui.mall.MallDetailActivity;

import butterknife.Bind;

/**
 * Created by yukai on 16/10/17.
 */

public class ToolItemVH extends BaseViewHolder<ToolRepository> {
    @Bind(R.id.iv_mall_item)
    ImageView mIvMallItem;
    @Bind(R.id.tv_mall_item_name)
    TextView mTvMallItemName;
    @Bind(R.id.tv_mall_item_price)
    TextView mTvMallItemPrice;
    @Bind(R.id.tv_mall_item_count)
    TextView mTvMallItemCount;
    /*@Bind(R.id.iv_mall_item)
    ImageView mIvMallItem;
    @Bind(R.id.tv_mall_item_name)
    TextView mTvMallItemName;
    @Bind(R.id.tv_mall_item_price)
    TextView mTvMallItemPrice;
    @Bind(R.id.tv_mall_item_stock)
    TextView mTvMallItemStock;*/

    public ToolItemVH(View v) {
        super(v);
    }

    @Override
    public int getType() {
        return R.layout.item_mall;
    }

    @Override
    public void onBindViewHolder(View view, ToolRepository obj) {
        mImageUtil.loadUrlImage(obj.data.getImage(), mIvMallItem);
        mTvMallItemName.setText(obj.data.getName());
        mTvMallItemCount.setText(obj.data.getSellcount() + "");
        mTvMallItemPrice.setText("￥" + String.format("%.2f", obj.data.getPrice()));
//        mTvMallItemStock.setText(obj.data.getCount() + "");
        view.setOnClickListener(v -> {
            Intent intent = new Intent(mContext, MallDetailActivity.class);
            intent.putExtra("goodsBean", obj.data);
            if (Build.VERSION.SDK_INT > 20) {
                mContext.startActivity(new Intent(mContext, MallDetailActivity.class).putExtra("goodsBean", obj.data),
                        ActivityOptions.makeSceneTransitionAnimation((Activity) mContext, mIvMallItem, "shareAnim").toBundle());
            } else {
                mContext.startActivity(intent);
            }
        });
    }
}
